<?php
class DBConnect 
{
	protected $conn;

	function __construct()
	{
		$this->conn = mysql_connect("localhost", "root", "") 
			or die("Could not connect: " .mysql_error());
		mysql_select_db("nutrition2", $this->conn) 
			or die("Could not find database: " .mysql_error());
	}
	
	function loginCheck($username, $password)
	{
		
		$userQuery = mysql_query("select * from users where user_id = '$username'", $this->conn)
			or die("1: ".mysql_error());
		
		if(mysql_num_rows($userQuery) > 0)
		{
			echo "user exists";
			$loginQuery = mysql_query("select * from users where user_id ='$username' and password = '$password'", $this->conn)
			or die("2: ".mysql_error());
			
			return true;
		}
		else 
		{
			echo "No such user";
			return false;
		}

	}
}
// function dbConnect(){

// 	$dbConnect = mysql_connect("localhost", "root", "")
// 	or die("Unable to connect to server :".mysql_error());

// 	$selectDB = mysql_select_db("nutrition2", $dbConnect)
// 	or die("Unable to select DB: ".mysql_error());

// 	return $dbConnect;

// }

// function insertUser ($username, $pword, $height, $weight, $age, $gender, $activity)
// {
// 	$dbConnect= dbConnect();

// 	$user_query = 
// 	"insert into users (user_id, weight, height, age, activity, password, gender)
// 	values (\"$username\", \"$weight\", \"$height\", \"$age\", \"$activity\", \"$pword\", \"$gender\")";

// 	 mysql_query($user_query, $dbConnect)
// 		or die("Not inserted: ".mysql_error());
// }

// function insertFood ($fName, $calories)
// {
// 	$dbConnect= dbConnect();

// 	$food_query = "INSERT INTO foods_list (food_desc, food_cal)
// 			VALUES ('$fName', '$calories')";

// 	 mysql_query($food_query, $dbConnect);
// }

// function insertNutr ($nutr_desc, $units)

// {
// 	$dbConnect= dbConnect();

// 	$nutrient_query = 
// 	"insert into nutrient_desc(nutr_desc, units)
// 	values ('$nutr_desc', '$units')";

// 	$nutr_insert = mysql_query($nutrient_query, $dbConnect)
// 		or die("Cannot insert nutrient: ".mysql_error());

// }
?>